package com.wits.qso.entity;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import net.sf.json.JSONObject;
import net.sf.json.JsonConfig;
import net.sf.json.processors.JsonBeanProcessor;

import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Parameter;

import com.wits.platform.common.JsonDateValueProcessor;
import com.wits.platform.common.utils.DateUtil;
import com.wits.platform.entity.BaseEntity;
import com.wits.platform.entity.Department;
import com.wits.platform.entity.Employee;
import com.wits.qso.common.enumerate.HelpQueStatus;

@Entity
@Table(name="qso_helpque")
public class HelpQue extends BaseEntity{

	/**
	 * 
	 */
	private static final long serialVersionUID = -8693321330537960368L;

	/** 队列代码  **/
	private String hpqId;
	
	/** 基本课表编号  **/
	private String bTableId;

	/** 课程编号  **/
	private String courseId;
	
	/** 求教学生 **/
	private Student student;

	/** 求教问题 **/
	private String hpqQuestion;
	
	/** 问题状态  **/
	private String hpqStatus;
	
	/** 虚机编号 **/
	private String vmId;
	
	/** 解答老师 **/
	private String teaId;
	
	/** 解决问题的讨论组id **/
	private String groupId;

	private String teaName;

	/** 时间起 **/
	private String bTableTimeF;
	
	/** 时间止 **/
	private String bTableTimeT;

	@Id
	@GenericGenerator(name = "idGen", 
					strategy = "com.wits.platform.common.id.generator.IDGenerator",
					parameters={ 
								@Parameter(name = "segment_value", value = "QSO_HPQ_ID"), //需指定
								@Parameter(name="table_name",value="wits_id_generator"),
								@Parameter(name="value_column_name",value="gen_value"),
								@Parameter(name="segment_column_name",value="gen_name"),
								@Parameter(name="segment_value_length",value="10"),
								@Parameter(name="sq_format",value="%010d"), //需指定
								@Parameter(name="sq_prefix",value="") //需指定
					})
	@GeneratedValue(generator = "idGen")
	@Column(name="hpq_id",length=36)
	public String getHpqId() {
		return hpqId;
	}

	public void setHpqId(String hpqId) {
		this.hpqId = hpqId;
	}

	@Column(name="btable_id",length=36)
	public String getbTableId() {
		return bTableId;
	}

	public void setbTableId(String bTableId) {
		this.bTableId = bTableId;
	}

	@Column(name="course_id",length=36)
	public String getCourseId() {
		return courseId;
	}

	public void setCourseId(String courseId) {
		this.courseId = courseId;
	}

	
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="stu_id")
	public Student getStudent() {
		return student;
	}

	public void setStudent(Student student) {
		this.student = student;
	}




	@Column(name="hpq_question")
	public String getHpqQuestion() {
		return hpqQuestion;
	}

	public void setHpqQuestion(String hpqQuestion) {
		this.hpqQuestion = hpqQuestion;
	}

	@Column(name="hpq_status",length=2)
	public String getHpqStatus() {
		return hpqStatus;
	}

	public void setHpqStatus(String hpqStatus) {
		this.hpqStatus = hpqStatus;
	}

	@Column(name="vm_id",length=36)
	public String getVmId() {
		return vmId;
	}

	public void setVmId(String vmId) {
		this.vmId = vmId;
	}

	@Column(name="tea_id",length=36)
	public String getTeaId() {
		return teaId;
	}

	public void setTeaId(String teaId) {
		this.teaId = teaId;
	}

	@Column(name="tea_name",length=50)
	public String getTeaName() {
		return teaName;
	}

	public void setTeaName(String teaName) {
		this.teaName = teaName;
	}
	
	@Column(name="group_id",length=36)
	public String getGroupId() {
		return groupId;
	}

	public void setGroupId(String groupId) {
		this.groupId = groupId;
	}
	
	@Column(name="btable_time_f",length=5)
	public String getbTableTimeF() {
		return bTableTimeF;
	}
	
	public void setbTableTimeF(String bTableTimeF) {
		this.bTableTimeF = bTableTimeF;
	}

	@Column(name="btable_time_t",length=5)
	public String getbTableTimeT() {
		return bTableTimeT;
	}

	public void setbTableTimeT(String bTableTimeT) {
		this.bTableTimeT = bTableTimeT;
	}

	@Override
	public String display() {
		// TODO Auto-generated method stub
		return null;
	}

	private static JsonConfig jsonConfig = new JsonConfig();


	@Transient
	public static JsonConfig getJsonConfig() {
		return jsonConfig;
	}
	
	static{
		jsonConfig.registerJsonBeanProcessor(HelpQue.class, new JsonBeanProcessor(){
			@Override
			public JSONObject processBean(Object bean, JsonConfig jConf) {
				if(!(bean instanceof HelpQue)){
		            return new JSONObject(true);
		         }
				HelpQue hq = (HelpQue) bean;
				Student stu=hq.getStudent();
		         return new JSONObject()
		            .element("hpqId",hq.getHpqId())
		            .element("hpqQuestion",hq.getHpqQuestion())
		            .element("dateCre", DateUtil.format(hq.getDateCre()))
		            .element("hpqStatus",HelpQueStatus.getDisplay(hq.hpqStatus))
		            .element("status",hq.hpqStatus)
		            .element("stuId",stu.getStuId())
		            .element("stuName",stu.getStuName())
		            .element("teaName",hq.getTeaName())
		            .element("groupId",hq.getGroupId())
		         	.element("userId", stu.getStuUserId());
		      }
			});
		
		
	}
	@Override
	public String toString() {
		return JSONObject.fromObject(this,jsonConfig).toString();
	}
	
	
};